<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增角色')" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-role-add">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">仓库名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="wareName" id="roleName" required>
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填项，不超过30个字</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">仓库地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="wareAddress" id="wareAddress" required>
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填项，不超过300个字</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">所属区域：</label>
				<div class="col-sm-4">
					<select id="pr" class="form-control form-inline">省
						<option>请选择</option>
						<option th:each="pr:${prs}" th:value="${pr.provId}" th:text="${pr.provName}"></option>
					</select >
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必填项.</span>
				</div>
				<div class="col-sm-4">
					<select id="city" name="sysCityId" class="form-control form-inline">市
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">负责人：</label>
				<div class="col-sm-8">
					<select id="user" name="sysChargeUserId" class="form-control form-inline">
						<option>请选择</option>
						<option th:each="u:${users}" th:value="${u.userId}" th:text="${u.userName}"></option>
					</select>
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 只能是财务部员工.</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="repoDesc" class="form-control" type="text">
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 可选项.</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<select id="" name="repoStatus" class="form-control form-inline">
						<option value="0">不可用</option>
						<option value="1">可用</option>
					</select>
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 必选项.</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">创建人：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" th:value="${user.userName}" disabled readonly required>
					<span class="help-block m-b-none" ><i class="fa fa-info-circle"></i>不可修改</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">创建时间：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="createTime"  th:value="${#dates.format(#dates.createNow(),'yyyy年MM月dd日')}" readonly required>
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 不可修改</span>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: ztree-js" />
	<script type="text/javascript">
		$("#pr").change(function () {
			$.get("/storage/ware/city/" + $("#pr").val(),{},function (data) {
				let options = '';
				for (let i = 0; i < data.length; i++) {
					options += '<option value="'+ data[i].cityId +'">'+ data[i].cityName +'</option>'
				}

				$("#city").html(options);
			})
		})

		/*$("#form-role-add").validate({
			rules:{
				onkeyup: false,
				roleName:{
					remote: {
		                url: ctx + "system/role/checkRoleNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"roleName" : function() {
		                		return $.common.trim($("#roleName").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				roleKey:{
					remote: {
		                url: ctx + "system/role/checkRoleKeyUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"roleKey" : function() {
		                        return $.common.trim($("#roleKey").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				roleSort:{
					digits:true
				},
			},
			messages: {
		        "roleName": {
		            remote: "角色名称已经存在"
		        },
		        "roleKey": {
		            remote: "角色权限已经存在"
		        }
		    },
		    focusCleanup: true
		});*/
		
		$('input').on('ifChanged', function(obj){
			var type = $(this).val();
			var checked = obj.currentTarget.checked;
			if (type == 1) {
			    if (checked) {
			        $._tree.expandAll(true);
			    } else {
			        $._tree.expandAll(false);
			    }
			} else if (type == "2") {
			    if (checked) {
			        $._tree.checkAllNodes(true);
			    } else {
			        $._tree.checkAllNodes(false);
			    }
			} else if (type == "3") {
			    if (checked) {
			        $._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
			    } else {
			        $._tree.setting.check.chkboxType = { "Y": "", "N": "" };
			    }
			}
		})
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }
	
		function add() {
			var wareName = $("input[name='wareName']").val();
			var wareAddress = $("input[name='wareAddress']").val();
			var sysCityId = $("select[name='sysCityId']").val();
			var sysChargeUserId = $("select[name='sysChargeUserId']").val();
			var repoStatus = $("select[name='repoStatus']").val();
			var repoDesc = $("input[name='repoDesc']").val();
			var createTime = $("input[name='createTime']").val();
			var sysCreateUserId = $("input[name='sysCreateUserId']").val();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "storage/ware/addRepo",
				data : {
					"wareName": wareName,
					"wareAddress": wareAddress,
					"sysCityId": sysCityId,
					"sysChargeUserId": sysChargeUserId,
					"repoStatus": repoStatus,
					"repoDesc": repoDesc,
					"sysCreateUserId": sysCreateUserId
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
	</script>
</body>
</html>
